<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:mo="https://gitee.com/aun/tentime">
<head th:replace="/common/template :: header(~{::title},~{::link},~{::style})">
    <link rel="stylesheet" th:href="@{/lib/zTree_v3/css/zTreeStyle/zTreeStyle.css}" type="text/css">
    <style type="text/css">
	    .layui-form-radio {margin: 0px 5px 0 0 !important;}
	    .layui-input-block {margin-left: 0px!important;}
	</style>
</head>
<body>
<div class="layui-form tentime-compile">
    <form id="inputForm" th:object="${entity}" class="layui-form">
        <input type="hidden" name="id" th:if="${entity}" th:value="${entity.id}"/>
        <div class="layui-form-item">
	        <div class="layui-inline">
	            <label class="layui-form-label required">用户名</label>
	            <div class="layui-input-inline">
	                <input class="layui-input" lay-verify="required" type="text" name="username"  placeholder="请输入用户名" th:value="${entity?.username}">
	            </div>
	        </div>
	        <div class="layui-inline">
	            <label class="layui-form-label required">用户昵称</label>
	            <div class="layui-input-inline">
	                <input class="layui-input" lay-verify="required" type="text" name="nickname" placeholder="请输入用户昵称" th:value="${entity?.nickname}">
	            </div>
	        </div>
        </div>
        <div class="layui-form-item" th:if="!${entity}">
	        <div class="layui-inline">
	            <label class="layui-form-label required">用户密码</label>
	            <div class="layui-input-inline">
	                <input class="layui-input" lay-verify="required" type="password" name="password" placeholder="请输入用户密码">
	            </div>
            </div>
	        <div class="layui-inline">
	            <label class="layui-form-label required">确认密码</label>
	            <div class="layui-input-inline">
	                <input class="layui-input" lay-verify="required|confirmPass" type="password" name="confirm" placeholder="再一次输入密码">
	            </div>
	        </div>
        </div>
        <div class="layui-form-item">
        	<div class="layui-inline">
	            <label class="layui-form-label required">所在部门</label>
	            <div class="layui-input-inline">
	                <input class="layui-input select-tree" th:attr="data-url=@{/system/dept/list}, data-value=${entity?.dept?.id}"
	                       type="text" name="dept" lay-verify="required"  placeholder="请选择所在部门" th:value="${entity?.dept?.title}">
	            </div>
            </div>
            <div class="layui-inline">
	            <label class="layui-form-label">电话号码</label>
	            <div class="layui-input-inline">
	                <input class="layui-input" type="text" name="phone" placeholder="请输入电话号码" th:value="${entity?.phone}">
	            </div>
            </div>
        </div>
        <div class="layui-form-item">
        	<div class="layui-inline">
	            <label class="layui-form-label">邮箱</label>
	            <div class="layui-input-inline">
	                <input class="layui-input" type="text" name="email" placeholder="请输入邮箱" th:value="${entity?.email}">
	            </div>
            </div>
	        <div class="layui-inline">
	            <label class="layui-form-label">选择性别</label>
	            <div class="layui-input-inline">
	                <input type="radio" name="sex" value="1" title="男" checked>
	                <input type="radio" name="sex" value="2" title="女" th:checked="${entity?.sex} eq 2">
	            </div>
	        </div>
        </div>
        
        <div class="layui-form-item">
        	<label class="layui-form-label">角色</label>
            <div class="layui-input-block">
                <input th:each="item:${roleList}" type="checkbox" name="roleId" th:title="${item.title}"
                       th:value="${item.id}" th:checked="${#sets.contains(authRoles, item)}" lay-skin="primary">
            </div>
        </div>
        
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入内容" class="layui-textarea" name="remark" style="width:450px;">[[${entity?.remark}]]</textarea>
            </div>
        </div>
        <div class="layui-form-item tentime-finally">
            <button class="layui-btn layui-btn-sm layui-btn-primary" lay-submit lay-filter="submit_button" shiro:hasAnyPermissions="system:user:add,system:user:edit"><i class="fa fa-check-circle"></i> 保存</button>
            <button class="layui-btn layui-btn-sm layui-btn-primary" onclick="closeWin();" type="button"><i class="fa fa-times-circle"></i> 关闭</button>
        </div>
    </form>
</div>
<script th:replace="/common/template :: common"></script>
<script type="text/javascript" th:src="@{/lib/zTree_v3/js/jquery.ztree.core.min.js}"></script>
<script type="text/javascript" th:src="@{/js/tentimeTree.js}"></script>
<script type="text/javascript">
    layui.use(['form'], function () {
        window.form = layui.form;
        form.verify({
            confirmPass:function(value){
                if($('input[name=password]').val() !== value) {
                    return '两次密码输入不一致！';
                }
            }
        });
        form.on("submit(submit_button)", function (data) {
        	$("#inputForm").ajaxSubmit({
				type : "post"
	            ,url : ctx + '/system/user/saveEntity'
	            ,success : function(data) {
	            	var code = data.code;
	            	var msg = data.msg;
	            	if (code == 200) {
	            		parent.layer.msg(msg, {icon: 1});
	            		closeWin();
	            		window.parent.reloadTable();
	            	} else {
	            		parent.layer.msg('数据验证失败：' + msg, {icon: 2});
	            	}
	            }
			});
       		return false;
       	});
    });
    //初始化部门树
    $.fn.selectTree();
</script>
</body>
</html>